import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.scss'
import { useAppSelector, useAppDispatch } from '@/store/index'
import { select_count, increment, Login, get_user_info } from '@/store/slice/user'
import { usePermissions } from '@/hooks/usePermissions'
function App() {
  const [count, setCount] = useState(0)

  const value = useAppSelector(select_count)
  const dispatch = useAppDispatch()
  const hanldClick = () => {
    dispatch(increment())
  }
  // const token = sessionStorage.getItem('token')
  // useEffect(() => {
  //   if (!token) {
  //     Navigate('/login')
  //   }
  // }, [Location.pathname])
  const onLogin = async () => {
    await dispatch(
      Login({
        username: 'hyh',
        password: 'hyh123',
        code: '1654',
        uuid: 'vtvMNmuQuVu0jzYzREtY'
      })
    )
    dispatch(get_user_info())
  }
  usePermissions()
  return (
    <>
      <button onClick={onLogin}>点击登录</button>
      <div>
        <a href='https://vitejs.dev' target='_blank' rel='noreferrer noopener'>
          <img src={viteLogo} className='logo' alt='Vite logo' />
        </a>
        <a href='https://react.dev' target='_blank' rel='noreferrer noopener'>
          <img src={reactLogo} className='logo react' alt='React logo' />
        </a>
      </div>
      <h1 className='text-[red]'>Vite {value}</h1>
      <button onClick={hanldClick}>点击加一</button>
      <div className='card'>
        <button onClick={() => setCount(count => count + 1)}>count is {count}</button>
        <p>
          Edit <code>src/App.tsx</code> and save to test HMR
        </p>
      </div>
      <br />
      <br />
      <br />
      <br />
      <br />
      <p className='read-the-docs'>Click on the Vite and React logos to learn more</p>

    </>
  )
}

export default App
